package com.HomeWorkhsp.chapter15.generic;

import java.util.ArrayList;
import java.util.Comparator;

public class GenericExercise02 {
    public static void main(String[] args) {
        ArrayList<Employee> arrayList = new ArrayList<>();
        arrayList.add(new Employee("wang", 20000, new MyDate(3,16,1999)));
        arrayList.add(new Employee("yao", 15000, new MyDate(4,20,1995)));
        arrayList.add(new Employee("li", 18000, new MyDate(10,2,1996)));

        System.out.println("排序前：");
        System.out.println(arrayList);
        arrayList.sort(new Comparator<Employee>() {
            @Override
            public int compare(Employee o1, Employee o2) {
                if (!(o1 instanceof Employee && o2 instanceof Employee)){
                    System.out.println("类型不正确");
                    return 0;
                }
                int i = o1.getName().compareTo(o2.getName());
                if (i != 0)
                    return i;
                else
                    return o1.getBirthday().compareTo(o2.getBirthday());
            }
        });
        System.out.println("排序后：");
        System.out.println(arrayList);

    }
}




